package com.cake.service;

import com.alibaba.fastjson.JSONObject;
import com.cake.util.HttpUtil;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by XuRui's Hands.
 * User:XuRui
 * Date:2017/1/4
 * Time:23:40
 */
public class WeixinService {
    @Scheduled(cron ="* */30 */1 * * ?")
    public void getAccessToken(){
        {
            String url = "https://api.weixin.qq.com/cgi-bin/token";
            Map<String,String> params = new TreeMap<String,String>();
            params.put("grant_type", "client_credential");
            params.put("appid","wx0b788acbf4fca179");
            params.put("secret","ccac4297b99f71c36022e04c7e5ff31a");
            String returnValue = HttpUtil.httpGet(url,params);
            JSONObject json = new JSONObject().parseObject(returnValue);
            System.out.println(json.getString("access_token"));
            System.out.println(new Date().getTime());
        }
    }
}
